<template>
    <!-- 投保单列表页  -->
    <div>
        <el-table v-if="tableData3.length>0" :data="tableData3" border style="width: 100%" >
            <el-table-column prop="SALESDETAIL.SALESDETAIL_ID" label="投保单号" width="180">
            </el-table-column>           
            <el-table-column prop="SALESDETAIL.SALESDETAIL_SALESTIME" label="销售时间" width="180" :formatter="localDataFomatter">
            </el-table-column>
            <el-table-column prop="CUSTOM.CUSTOM_NAME" label="被保险人姓名" width="180">
            </el-table-column>
            <el-table-column prop="SALESDETAIL.PRODUCE_NAME" label="产品类型" width="200">
            </el-table-column>
            <el-table-column prop="SALESDETAIL.SALESDETAIL_OLD" label="投保年龄" width="200">
            </el-table-column>
            <el-table-column prop="SALESDETAIL.SALESDETAIL_MONEY" label="保费金额" width="200">
            </el-table-column>
            <el-table-column prop="SALESDETAIL.SALESDETAIL_ADDMONEY" label="增额保费" width="200">
            </el-table-column>

            <el-table-column label="操作" width="220" fixed="right">
                <template scope="scope">
                    <el-button type="text" size="media" v-if="type=='客户信息审核'" @click="goCheckF(scope.row)">
                        <i class="el-icon-view"> 审核</i>
                    </el-button>
                    <el-button type="text" size="media" v-if="type=='投保单审核'" @click="goCheckS(scope.row)">
                        <i class="el-icon-view"> 审核</i>
                    </el-button>
                    <el-button type="text" size="media" v-if="type=='修改'" @click="changeInformation(scope.row)">
                        <i class="el-icon-view"> 修改</i>
                    </el-button>
                      <el-button type="text" size="media" v-if="type=='提交'" @click="goConmit(scope.row)">
                        <i class="el-icon-view"> 修改</i>
                    </el-button>
                    <el-button type="text" size="media" v-if="type=='上传下载'" @click="goDowloade(scope.row)">
                        <i class="el-icon-view"> 下载</i>
                    </el-button>
                    <el-button type="text" size="media" v-if="type=='上传下载'" @click="goUploade(scope.row.SALESDETAIL.SALESDETAIL_ID)">
                        <i class="el-icon-view"> 上传</i>
                    </el-button>
                    <el-button type="text" size="media" v-if="type=='缴费确认'" @click="goCenter(scope.row.SALESDETAIL.SALESDETAIL_ID)">
                        <i class="el-icon-view"> 确认</i>
                    </el-button>
                    <el-button type="text" size="media" v-if="type=='到账确认'" @click="goFinace(scope.row.SALESDETAIL.SALESDETAIL_ID)">
                        <i class="el-icon-view"> 确认</i>
                    </el-button>
                    <el-button type="text" size="media" v-if="type=='保险单上传'" @click="goDocument(scope.row.SALESDETAIL.SALESDETAIL_ID)">
                        <i class="el-icon-view"> 上传</i>
                    </el-button>
                    <el-button type="text" size="media" @click="goFeiZhi(scope.row)">
                        <i class="el-icon-view"> 废止</i>
                    </el-button>
                </template>
            </el-table-column>
        </el-table>
        <div class="block">
            <el-pagination @current-change="handleCurrentChange" :current-page="currentPage1" :page-size="10" layout="total, prev, pager, next" :total="pagecount">
            </el-pagination>
        </div>
    </div>
</template>
<script>
import api from "@/js/api";
import { mapState } from "vuex";
export default {
  data() {
    return {
      pagecount: 0,
      currentPage1: 1,
      tableData3: []
    };
  },
  computed: mapState({
    saleDetail: state => state.SealDetail.model
  }),
  props: {
    id: {
      type: {
        type: String,
        default: ""
      }
    },
    type: {
      type: String,
      default: "待沟通"
    }
  },
  methods: {
    birthdayFomatter(row, column, cellValue) {
      cellValue = cellValue + "Z";
      return new Date(cellValue).toLocaleDateString();
    },
    dataFomatter(row, column, cellValue) {
      cellValue = cellValue + "Z";
      return new Date(cellValue).toLocaleString();
    },
    localDataFomatter(row, column, cellValue) {
      cellValue = cellValue + "Z";
      var data = new Date(cellValue);
      var dataString =
        data.getFullYear() +
        "/" +
        (data.getMonth() + 1 >= 10
          ? data.getMonth() + 1
          : "0" + (data.getMonth() + 1)) +
        "/" +
        (data.getDate() >= 10 ? data.getDate() : "0" + data.getDate()) +
        " " +
        (data.getHours() >= 10 ? data.getHours() : "0" + data.getHours()) +
        ":" +
        (data.getMinutes() >= 10 ? data.getMinutes() : "0" + data.getMinutes());
      return dataString;
    },
    cloneDate(cloneObj) {
      //传递数据为对象 所以更改后会改变列表数据 1.深拷贝2.关闭时，重新获取数据； 采用了第二种(后期可更换第一种，减少请求)

      if (cloneObj.SALESDETAIL.SALESDETAIL_APPLYTIME)
        cloneObj.SALESDETAIL.SALESDETAIL_APPLYTIME =
          cloneObj.SALESDETAIL.SALESDETAIL_APPLYTIME + "Z";
      if (cloneObj.SALESDETAIL.SALESDETAIL_STARTTIME)
        cloneObj.SALESDETAIL.SALESDETAIL_STARTTIME =
          cloneObj.SALESDETAIL.SALESDETAIL_STARTTIME + "Z";
      if (cloneObj.SALESDETAIL.SALESDETAIL_ENDTIME) 
        cloneObj.SALESDETAIL.SALESDETAIL_ENDTIME =
         cloneObj.SALESDETAIL.SALESDETAIL_ENDTIME + "Z";     

      this.$emit("changeInformation", cloneObj.CUSTOM.CUSTOM_ID);
      this.$store.commit("changer", cloneObj.SALESDETAIL);
      this.saleDetail.CUSTOM = cloneObj.CUSTOM;
      this.saleDetail.RELATIONPEOPLEs = cloneObj.SALESDETAIL.RELATIONPEOPLEs;
      this.saleDetail.QUESTION = cloneObj.SALESDETAIL.QUESTION;
    },
    changeInformation(obj) {
      //传递数据为对象 所以更改后会改变列表数据 1.深拷贝2.关闭时，重新获取数据； 采用了第二种(后期可更换第一种，减少请求)
      var cloneObj = JSON.parse(JSON.stringify(obj));
      this.cloneDate(cloneObj);
    },
    //确认提交
    goConmit(obj) {
      //传递数据为对象 所以更改后会改变列表数据 1.深拷贝2.关闭时，重新获取数据； 采用了第1种(后期可更换第一种，减少请求)
      var cloneObj = JSON.parse(JSON.stringify(obj));
      this.cloneDate(cloneObj);
    },
    handleCurrentChange(val) {
      this.currentPage1 = val;
      this.getDate();
    },
    //审核
    goCheckF(obj) {
      this.$emit("goCheckF");
      //传递数据为对象 所以更改后会改变列表数据 1.深拷贝2.关闭时，重新获取数据； 采用了第二种(后期可更换第一种，减少请求)
      var cloneObj = JSON.parse(JSON.stringify(obj));
      this.cloneDate(cloneObj);
    },
    goCheckS(obj) {
      this.$emit("goCheckS", obj);
      var cloneObj = JSON.parse(JSON.stringify(obj));
      this.cloneDate(cloneObj);
    },
    goUploade(id) {
      this.$emit("goUploade", id);
    },
    goDowloade(obj) {
      // console.log(11);
      // this.$emit("goDowloade", id);
      api.SaledetailGetDoc(
        this,
        { id: obj.SALESDETAIL.SALESDETAIL_ID },
        function(msg) {
          var url = msg.Result.url;
          var trueUrl = api.download(url);
          window.open(trueUrl);
        }
      );
    },
    goCenter(id) {
      this.$emit("goCenter", id);
    },
    goDocument(id) {
      this.$emit("goDocument", id);
    },
    //到账确认
    goFinace(id) {
      this.$emit("goFinace", id);
    },
    //废止方法
    goFeiZhi(obj) {
      obj.SALESDETAIL.SALESDETAIL_CHECKSTATE = "废止";
      var data = {
        SALESDETAIL: obj.SALESDETAIL,
        CUSTOM: obj.CUSTOM
      };
      // console.log(data);
      api.SaledetailUpdate(this, data);
    },
    getDate() {
      var data = {
        state: "",
        pageSize: 10,
        pageIndex: this.currentPage1
      };
      //未提交 客户信息审核 需上传投保单 投保单审核 需缴费确认 需到账确认 需保险单上传 审核不通过
      switch (this.type) {
        case "客户信息审核":
          data.state = "客户信息审核";
          break;
        case "投保单审核":
          data.state = "投保单审核";
          break;
        case "修改":
          data.state = "审核不通过";
          break;
        case "上传下载":
          data.state = "需上传投保单";
          break;
        case "缴费确认":
          data.state = "需缴费确认";
          break;
        case "到账确认":
          data.state = "需到账确认";
          break;
        case "保险单上传":
          data.state = "需保险单上传";
          break;
        case "提交":
          data.state = "未提交";
          break;
      }
      let that = this;
      api.SaledetailSelect(that, data, function(msg) {
        that.tableData3 = msg.Result;
        that.pagecount = msg.ListCount;
      });
    }
  },
  created() {
    this.getDate();
    this.$store.commit("changer", {});
  }
};
</script>
